package es.valma.VideoClub.html.transformador;

import java.io.FileInputStream;
import java.io.FileOutputStream;

import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;

public class VideoClubSvGeneradorXmlXsl {

	public static String tranformadorXmlXsl(String xml,String xsl){
		String retorno="";
		TransformerFactory tFactory =TransformerFactory.newInstance();
		try{
			String rutaXSL="./login/"+xsl;
			String rutaXML="./login/"+xml;
	        Transformer transformer =tFactory.newTransformer(new StreamSource(rutaXSL));
	        FileOutputStream fileTmp=new FileOutputStream("./tmp");
	        transformer.transform(new StreamSource(rutaXML),new StreamResult(fileTmp));
	        
	        FileInputStream file = new FileInputStream ("./tmp");
	        long tcalc ;
	        long begin = System.currentTimeMillis() ;
	        byte[] b = new byte[file.available ()];
	        file.read(b);
	        file.close ();
	        String result = new String (b);
	        /* */
	        tcalc = (System.currentTimeMillis() - begin);
	        System.out.println("Compute time: " + tcalc + " ms for " + result.length() + " bytes.");
	        
	        
	        
	        
	        retorno=result;
		}catch(Throwable th){
			System.err.println("ERROR!!!!! Transformando XmlXsl a HTML");
			System.out.println("ERROR!!!!! Transformando XmlXsl a HTML");
		}
	    return retorno;
	}
}
